#!/bin/sh

CurrentMouthDay=`date +%Y-%m-01`
Today=`date  "+%Y-%m-%d"`
Today1=`date  "+%Y-%m-%d %H:%m"`
CurrentDay=`date +%d`
Lastday=`date -d 'last day' +%Y-%m-%d`
LastMouthStartDay=`date -d "$CurrentMouthDay last month" +%Y-%m-%d`
LastMouthEndDay=`date -d "$CurrentMouthDay last day" +%Y-%m-%d`

LastMouthStartDayToNum=`echo $LastMouthStartDay|sed 's/-//g'`
LastMouthEndDayToNum=`echo $LastMouthEndDay|sed 's/-//g'`

CurrentMouthStartDay=`echo $CurrentMouthDay|sed 's/-//g'`
CurrentEndDay=`echo $Today|sed 's/-//g'`

DiffDays=`expr $LastMouthEndDayToNum - $LastMouthStartDayToNum + 1`
CurrentDiffDays=`expr $CurrentEndDay - $CurrentMouthStartDay + 1`

P95mouth=$(echo "scale=0;$[$DiffDays*24*12*5]/100" | bc) 
P95current=$(echo "scale=0;$[$CurrentDiffDays*24*12*5]/100" | bc) 

echo $LastMouthStartDayToNum-$LastMouthEndDayToNum "Total":$DiffDays "days" "P95":$P95mouth
echo $CurrentEndDay-$CurrentMouthStartDay "Total":$CurrentDiffDays "days" "P95":$P95current
#客户端口

sql_usr=root
sql_pwd=123456
sql_db=traffic

next() {
    printf "%-80s\n" "-" | sed 's/\s/-/g'
}


xipu_port=`cat /var/www/traffic/test/xipu_id |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
xipu24=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS  out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN                   ($xipu_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

chengdu_port=`cat /var/www/traffic/test/chengdu_id |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
chengdu20=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN                ($chengdu_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`


baishan16_port=`cat /var/www/traffic/test/baishan_id |sed -n "1,16p" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baishanbaoji16=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS     out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishan16_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

baishan12_port=`cat /var/www/traffic/test/baishan_id |grep  "鸡电信白山120G" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baishanbaoji12=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id   IN ($baishan12_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

#baishan4new_port=`cat /var/www/traffic/test/baishan_id |sed -n "28,31p" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#baishanbaoji4new=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishan4new_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

baishan4city_port=`cat /var/www/traffic/test/baishan_id |sed -n "18,21p" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baishanbaoji4city=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishan4city_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

baishanweinan_port=`cat /var/www/traffic/test/operators_id|grep "白山" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baishanweinan20=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishanweinan_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

baishanweinan_port10=`cat /var/www/traffic/test/operators_id |grep "渭南白山专网" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baishanweinan10=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishanweinan_port10)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

jinshanctcc16_port=`cat /var/www/traffic/test/jinxun_id |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
jinshanctcc16=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN                ($jinshanctcc16_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

jinshanbaoji_port=`cat /var/www/traffic/test/xa_pid |grep "金迅-宝鸡"  |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
jinshanbaoji=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($jinshanbaoji_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

wangsu4_port=`cat /var/www/traffic/test/xa_pid |grep "网宿" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
wangsu4p1_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($wangsu4_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`


wangsu2_port=`cat /var/www/traffic/test/xa_pid |grep "网宿-西安bgp" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
wangsu2p1_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($wangsu2_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

#西安资源
#baishanxa_port=`cat /var/www/traffic/test/xa_pid |grep "白山" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#baishanxa1_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($baishanxa_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

dianlian_port=`cat /var/www/traffic/test/xa_pid |grep "电联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
dianlian2_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($dianlian_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

cqt_port=`cat /var/www/traffic/test/xa_pid |grep "承启通" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
cqt7_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($cqt_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

yunduan_port=`cat /var/www/traffic/test/xa_pid |grep "云端移动" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
yunduan_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($yunduan_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

yunduancucc_port=`cat /var/www/traffic/test/xa_pid |grep "云端联通" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
yunduancucc1_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($yunduancucc_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

yundi_port=`cat /var/www/traffic/test/xa_pid |grep "云堤" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
yundi1_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($yundi_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

guangtong_port=`cat /var/www/traffic/test/xa_pid |grep -w "光通" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
gt_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($guangtong_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

ddos40_port=`cat /var/www/traffic/test/xa_pid |grep "ddos-光通40" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
gtddos40_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($ddos40_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

ddos800_port=`cat /var/www/traffic/test/xa_pid |grep "ddos-光通800" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
gtddos800_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($ddos800_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

thyc_port=`cat /var/www/traffic/test/xa_pid |grep "天合高防" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
thyc800_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($thyc_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

#yuntu_port=`cat /var/www/traffic/test/xa_pid |grep "云图" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#yuntucmcc_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($yuntu_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

tiandi_port=`cat /var/www/traffic/test/xa_pid |grep "天地祥云" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
tiandicucc_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN ($tiandi_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

xaxipu_port=`cat /var/www/traffic/test/xa_pid |grep "咸阳西普" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
xaxipucucc_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($xaxipu_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

xath_port=`cat /var/www/traffic/test/xa_pid |grep "天互" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
xathDX_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($xath_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

guandxath_port=`cat /var/www/traffic/test/operators_id |grep "天互" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
xathgd_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($guandxath_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

guandjhy_port=`cat /var/www/traffic/test/operators_id |grep "鲸禾云" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
gdjhy_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($guandjhy_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`

#guandxhdz_port=`cat /var/www/traffic/test/operators_id |grep "西航电子" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#gdxhdz_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($guandxhdz_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`
next

#95求和
#ChengDu_95=`awk '{sum += $1};END {print sum/1000}' $chengdu_dir/*.95`

#合并端口单位转换
xipu_max=$(echo "scale=2;$xipu24/1000000000" |bc)G
chengdu_max=$(echo "scale=2;$chengdu20/1000000000" |bc)G
baishanbaoji16_max=$(echo "scale=2;$baishanbaoji16/1000000000" |bc)G
baishanbaoji12_max=$(echo "scale=2;$baishanbaoji12/1000000000" |bc)G
#baishanbaoji4new_max=$(echo "scale=2;$baishanbaoji4new/1000000000" |bc)
baishanbaoji4city_max=$(echo "scale=2;$baishanbaoji4city/1000000000" |bc)G
baishanweinan_max=$(echo "scale=2;$baishanweinan20/1000000000" |bc)G
baishanweinan10_max=$(echo "scale=2;$baishanweinan10/1000000000" |bc)G
#jinshanctcc16_max=$(echo "scale=2;$jinshanctcc16/1000000000" |bc)
jinshanbaoji_max=$(echo "scale=2;$jinshanbaoji/1000000" |bc)M
wangsu4p_max=$(echo "scale=2;$wangsu4p1_max/1000000000" |bc)G
wangsu2p_max=$(printf "%.2f" `echo "scale=2;$wangsu2p1_max/1000000" |bc`)M

dianlian_max=$(printf "%.2f" `echo "scale=2;$dianlian2_max/1000000" |bc`)M
cqt_max=$(printf "%.2f" `echo "scale=2;$cqt7_max/1000000000" |bc`)G
yunduancmcc_max=$(echo "scale=2;$yunduan_max/1000000000" |bc)G
yunduancucc_max=$(echo "scale=2;$yunduancucc1_max/1000000" |bc)M
yundi_max=$(echo "scale=2;$yundi1_max/1000000" |bc)M
#guangtong_max=$(echo "scale=2;$gt_max/1000000000" |bc)
guangtong_max=$(printf "%.2f" `echo "scale=2;$gt_max/1000000" |bc`)M
ddos40_max=$(echo "scale=2;$gtddos40_max/1000000" |bc)M
ddos800_max=$(echo "scale=2;$gtddos800_max/1000000" |bc)M
thyc_max=$(printf "%.2f" `echo "scale=2;$thyc800_max/1000000000" |bc`)G
#yuntu_max=$(echo "scale=2;$yuntucmcc_max/1000000" |bc)M
tiandi_max=$(echo "scale=2;$tiandicucc_max/1000000000" |bc)G
#xipuxa_max=$(echo "scale=2;$xaxipucucc_max/1000000000" |bc)G
#baishanxa_max=$(echo "scale=2;$baishanxa1_max/1000000000" |bc)
xath_max=$(echo "scale=2;$xathDX_max/1000000" |bc)M
sgdxath_max=$(printf "%.2f" `echo "scale=2;$xathgd_max/1000000" |bc`)M
sgdjhy_max=$(echo "scale=2;$gdjhy_max/1000000" |bc)M
sgdxhdz_max=$(echo "scale=2;$gdxhdz_max/1000000" |bc)M
#
#运营商
yunduancmcc_port=`cat /var/www/traffic/test/xa_pid |grep "云端移动" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
yunduancmcc=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($yunduancmcc_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
yunduan_95th1000=$(echo "scale=2;$yunduancmcc/1000000" |bc)M
yunduan_95th1024=$(echo "scale=2;$yunduancmcc/1024/1024" |bc)M

guangdian_port=`cat /var/www/traffic/test/operators_id |grep "广电联通上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
guangdianUnicom=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($guangdian_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
guangdian_95th1000=$(echo "scale=2;$guangdianUnicom/1000000" |bc)M
guangdian_95th1024=$(echo "scale=2;$guangdianUnicom/1024/1024" |bc)M

#yidong_port=`cat /var/www/traffic/test/operators_id |grep "移动" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#xianyidong=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($yidong_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
#YD_95th1000=$(echo "scale=2;$xianyidong/1000000000" |bc)G
#YD_95th1024=$(echo "scale=2;$xianyidong/1024/1024/1024" |bc)G
#
xianyang_port=`cat /var/www/traffic/test/operators_id |grep "咸阳" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
xianyang=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS  out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($xianyang_port))   GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
Tel_95th1000=$(echo "scale=2;$xianyang/1000000000" |bc)G
Tel_95th1024=$(echo "scale=2;$xianyang/1024/1024/1024" |bc)G
#
liantong_port=`cat /var/www/traffic/test/operators_id |grep "联通上联20G" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
liantong2p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS    out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN            ($liantong_port))   GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
XAcucc_95th1000=$(echo "scale=2;$liantong2p/1000000000" |bc)G
XAcucc_95th1024=$(echo "scale=2;$liantong2p/1024/1024/1024" |bc)G
#
baijiTel37_port=`cat /var/www/traffic/test/operators_id |grep "宝鸡电信上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baijiTel37p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS    out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($baijiTel37_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
baijiTel_95th1000=$(echo "scale=2;$baijiTel37p/1000000000" |bc)G
baijiTel_95th1024=$(echo "scale=2;$baijiTel37p/1024/1024/1024" |bc)G
#
baijiTel20_port=`cat /var/www/traffic/test/operators_id |grep "云基地上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baijiTel20p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)    AS    out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($baijiTel20_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
baijiTel20_95th1000=$(echo "scale=2;$baijiTel20p/1000000000" |bc)G
baijiTel20_95th1024=$(echo "scale=2;$baijiTel20p/1024/1024/1024" |bc)G
#
baijicucc_port=`cat /var/www/traffic/test/operators_id |grep "宝鸡联通" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
baijicucc=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($baijicucc_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
baijicucc_95th1000=$(echo "scale=2;$baijicucc/1000000000" |bc)G
baijicucc_95th1024=$(echo "scale=2;$baijicucc/1024/1024/1024" |bc)G
#
weinanTel_port=`cat /var/www/traffic/test/operators_id |grep "渭南电信上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
weinanTel=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)    AS    out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($weinanTel_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
weinanTel_95th1000=$(echo "scale=2;$weinanTel/1000000000" |bc)G
weinanTel_95th1024=$(echo "scale=2;$weinanTel/1024/1024/1024" |bc)G
#
weinanTel_port8=`cat /var/www/traffic/test/operators_id |grep "渭南电信专网上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
weinanTel8p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits) AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN ($weinanTel_port8)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
weinanTelp8_95th1000=$(echo "scale=2;$weinanTel8p/1000000000" |bc)G
weinanTelp8_95th1024=$(echo "scale=2;$weinanTel8p/1024/1024/1024" |bc)G
#
#xakuxun_port=`cat /var/www/traffic/test/operators_id |grep "酷讯联通上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#xiankuxun8p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)  AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN       ($xakuxun_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
#xiankuxun_95th1000=$(echo "scale=2;$xiankuxun8p/1000000000" |bc)G
#xiankuxun_95th1024=$(echo "scale=2;$xiankuxun8p/1024/1024/1024" |bc)G
#
#xakuxunChengW_port=`cat /var/www/traffic/test/operators_id |grep "城网上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
#xiankuxunCw4p=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)    AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN       ($xakuxunChengW_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
#xiankuxunCW_95th1000=$(echo "scale=2;$xiankuxunCw4p/1000000000" |bc)G
#xiankuxunCW_95th1024=$(echo "scale=2;$xiankuxunCw4p/1024/1024/1024" |bc)G
#
###高防###
#
Tel_ddos_port=`cat /var/www/traffic/test/operators_id |grep "防御电信上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
Tel8_ddos=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)  AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN        ($Tel_ddos_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
Tel_ddos_95th1024=$(printf "%.2f" `echo "scale=2;$Tel8_ddos/1000/1000" |bc`)M
Tel8_ddos_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits,                  SUM(core_trafficlog.out_bits)  AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN        ($Tel_ddos_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit 1,1"|sed -n '2p'`
Tel_ddos_max_value=$(printf "%.2f" `echo "scale=2;$Tel8_ddos_max/1000/1000" |bc`)M
#
unicom_ddos_port=`cat /var/www/traffic/test/operators_id |grep "联通高防上联" |awk '{print $1}' |tr "\n" ","|sed -e 's/,$/\n/'`
unicom2_ddos=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)  AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN        ($unicom_ddos_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit ${P95current},1"|sed -n '2p'`
unicom_ddos_95th1024=$(printf "%.2f" `echo "scale=2;$unicom2_ddos/1024/1024/1024" |bc`)G
unicom2_ddos_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT out_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.out_bits)  AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$CurrentMouthDay' AND core_trafficlog.date < '$Today1' AND core_trafficlog.port_id IN        ($unicom_ddos_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY out_bits desc limit 1,1"|sed -n '2p'`
unicom2_ddos_max_value=$(printf "%.2f" `echo "scale=2;$unicom2_ddos_max/1024/1024/1024" |bc`)G
#-#
#xakuxuncucc_max=`mysql -u$sql_usr -p$sql_pwd -B $sql_db -e "SELECT in_bits FROM (SELECT core_trafficlog.date AS Col1, SUM(core_trafficlog.in_bits) AS in_bits, SUM(core_trafficlog.           out_bits)   AS out_bits FROM core_trafficlog WHERE (core_trafficlog.isvalid = 1 AND core_trafficlog.date >= '$Lastday' AND core_trafficlog.date < '$Today' AND core_trafficlog.port_id IN    ($unicom_ddos_port)) GROUP BY core_trafficlog.date ORDER BY NULL) subquery ORDER BY in_bits desc limit 1" |sed -n '2p'`
#xakuxununicom_ddos_max=$(printf "%.2f" `echo "scale=2;$xakuxuncucc_max/1024/1024/1024" |bc`)G
#

next

echo "${Lastday}日带宽使用情况

客户峰值流量统计：
1、【电信】电联多线1个万兆：${dianlian_max}
3、【联通】云端联通500M：${yunduancucc_max}
4、【三线】云堤电信/联通/移动带宽：${yundi_max}
6、【联通】天地祥云联通带宽：${tiandi_max}

7、【宝鸡电信-城网】西普240G：${xipu_max}
8、【宝鸡电信-专网】白山云160G：${baishanbaoji16_max}
   【宝鸡电信-城网】白山云40G：${baishanbaoji4city_max}
   【宝鸡电信-城网】白山云120G：${baishanbaoji12_max}
   【渭南电信-城网】白山云200G：${baishanweinan_max}
   【渭南电信-专网】100G：${baishanweinan10_max}
9、【宝鸡电信-城网】成都200G：${chengdu_max}
10、【宝鸡联通】金迅10G：${jinshanbaoji_max}
11、【宝鸡联通】网宿40G：${wangsu4p_max}
    【西咸联通】网宿5G：${wangsu2p_max}
12、【西咸联通】天互1G：${xath_max}
    【广电联通】天互：${sgdxath_max}
13、【广电联通】鲸禾云：${sgdjhy_max}


从1号至${CurrentDay}号流量总口：
【电信防御流量】峰值：${Tel_ddos_max_value}  （95结算）：${Tel_ddos_95th1024}
【联通防御流量】峰值：${unicom2_ddos_max_value} （95结算）：${unicom_ddos_95th1024}
【移动防御流量】峰值：0M （95结算）：0M （暂停）

【西咸电信20G】运营商95结算流量	${Tel_95th1024}	（客户95结算   ${Tel_95th1000})
【云端移动】运营商95结算流量	${yunduan_95th1024}	（客户95结算   ${yunduan_95th1000})
【西咸联通20G】运营商95结算流量	${XAcucc_95th1024}	（客户95结算   ${XAcucc_95th1000})
【广电联通500M】运营商95结算流量 ${guangdian_95th1024} （客户95结算   ${guangdian_95th1000})
【宝鸡联通40G】运营商95结算流量	${baijicucc_95th1024}	（客户95结算   ${baijicucc_95th1000})
【宝鸡电信370G-城网】运营商95结算流量	${baijiTel_95th1024}	（客户95结算   ${baijiTel_95th1000})
【宝鸡电信160G-专网】运营商95结算流量	${baijiTel20_95th1024}	（客户95结算   ${baijiTel20_95th1000})
【渭南电信200G-城网】运营商95结算流量	${weinanTel_95th1024}	（客户95结算   ${weinanTel_95th1000})
【渭南电信80G-专网】运营商95结算流量	${weinanTelp8_95th1024}	（客户95结算   ${weinanTelp8_95th1000})
" >/var/www/traffic/test/send.txt

next
